package com.shd.edanpei.presenter;

import android.os.Bundle;
import android.text.TextUtils;

import com.shd.edanpei.ui.activity.CreateStepActivity;
import com.shd.edanpei.base.BasePresenterImpl;
import com.shd.edanpei.common.Constant;
import com.shd.edanpei.base.dialog.DialogUtil;
import com.shd.edanpei.bean.CustomerBean;
import com.shd.edanpei.presenter.contract.PublishContract;
import com.shd.edanpei.util.ToastUtil;

/**
 * Created by mc on 2018/10/17.
 * 选择申请区域
 */

public class PublishPresenter extends BasePresenterImpl<PublishContract.PublishIView>
        implements PublishContract.PublishIPresenter {

    private Bundle bundle = new Bundle();
    private CustomerBean customerBean = new CustomerBean();

    public PublishPresenter(PublishContract.PublishIView mView) {
        super(mView);
    }

    @Override
    public void onAddress() {
        DialogUtil.addressPick(mBaseIView.getContext(), new DialogUtil.AddressListener() {
            @Override
            public void done(String address, String provinceCode, String cityCode, String districtCode) {
                customerBean.setArea(address);
                customerBean.setAreaCode(districtCode);
                customerBean.setGcityCode(cityCode);
                mBaseIView.setAddress(address);
            }
        });
    }

    @Override
    public void onCreate(int orderType) {
        if (TextUtils.isEmpty(customerBean.getArea())) {
            ToastUtil.showToast("请先选择申请区域");
            return;
        }
        bundle.clear();
        bundle.putInt(Constant.ORDER_TYPE, orderType);
        bundle.putParcelable(Constant.DATA, customerBean);
        mBaseIView.startActivity(CreateStepActivity.class, bundle);
    }
}
